package billeterie.Aspects;

import billeterie.Show;
import billeterie.User;

public aspect CreditValidatorAspect 
{
    pointcut creditValidation(Show currentShow, int ticketsCount, User user) :  execution(* User.buyTickets(Show, int)) 
			    																&& args(currentShow, ticketsCount)
			    																&& target(user);

	before(Show currentShow, int ticketsCount, User user) : creditValidation(currentShow, ticketsCount, user) 
	{
		double total = currentShow.getPrice() * ticketsCount;
		
		if(user.getCredit() >= total)
		{
			user.setCanBuy(true);
		}
		else
		{
			user.setCanBuy(false);
		}
		
	}
}